package com.neusoft.elmboot.service.impl;

import java.math.BigDecimal;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neusoft.elmboot.service.PointLogService;
import com.neusoft.elmboot.util.CommonUtil;
import com.neusoft.elmboot.mapper.PointLogMapper;
import com.neusoft.elmboot.po.PointLog;

@Service
public class PointLogServiceImpl implements PointLogService{

    
    @Autowired
    PointLogMapper PointLogMapper;

    @Override
    public int getPointLogByUserIdByTime(String userId) {
            return PointLogMapper.getPointLogByUserIdByTime(userId, CommonUtil.getCurrentDate());
        
    }

    @Override
    public int savePointLog(PointLog il,BigDecimal amount) {
        System.out.println(amount);
        for ( BigDecimal i = BigDecimal.ZERO;i.compareTo(amount) < 0 ; i = i.add(BigDecimal.ONE)) {
            il.setTime(CommonUtil.getCurrentDate());
            PointLogMapper.savePointLog(il);
        }
        return 1;
    }
    
    @Override
    public int deletePointLogByUserIdByTime(String userId, Integer count) {
    	return PointLogMapper.deletePointLogByUserIdByTime(userId, count);
    }
    
    @Override
    public int updatePointLog(String userId) {
    	return PointLogMapper.updatePointLog(userId, CommonUtil.getPreviousDate());
    }
    
    @Override
    public int getExpirationPointLogByUserId(String userId) {
    	String limitTime = CommonUtil.getExpirationDate();
    	return PointLogMapper.getExpirationPointLogByUserId(userId, limitTime);
    }
}
